<?php
include "includes/sesiones.php";
include "includes/comunes.php";


$where=" where sucursal=".$_SESSION['SucursalId'];
  if($_GET['fin']<>0)
      $where.=" and financiera=".trim($_GET['fin'])." ";
   if($_GET['estado']<>0)
      $where.=" and estado=".trim($_GET['estado'])." ";
       if($_GET['fdesde']<>"")
      $where.=" and fecha >='".trim($_GET['fdesde'])."' ";
    if($_GET['fhasta']<>"")
      $where.=" and fecha <='".trim($_GET['fhasta'])."' ";
$sql="select * from creditos ".$where." order by financiera,tipoplan";
//echo $sql;

$rescre= $consultar=  cons_ins($sql);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Creditos por Fecha</title>
<style type="text/css">
<!--
.Estilo1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; }
.Estilo3 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.Estilo6 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; }
.Estilo9 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 16px; }
.Estilo10 {font-size: 10px}
.Estilo14 {font-size: 9px}
-->
</style>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td height="53" colspan="2"><div align="center" class="Estilo1">CREDITOS PARA TODOS </div></td>
    <td width="14%"><div align="center" class="Estilo2">Fecha Emision: </div></td>
    <td width="18%"><div align="center" class="Estilo2">&nbsp;<?php echo date("d/m/Y");?></div></td>
    <td width="11%"><div align="center" class="Estilo2">Emitido por: </div></td>
    <td width="19%"><div align="center" class="Estilo2">&nbsp;<?php echo $_SESSION['Usuario'];?></div></td>
  </tr>
  <tr>
    <td width="19%" style="border-top: 1px solid #666666"><div align="left" class="Estilo6">Rango Fechas</div></td>
    <td width="19%" style="border-top: 1px solid #666666"><div align="left">Desde <?php echo format_fec($_GET['fdesde'],"/");?> - Hasta <?php echo format_fec($_GET['fhasta'],"/");?></div></td>
    <td style="border-top: 1px solid #666666"><div align="left" class="Estilo6">Financiera</div></td>
    <td style="border-top: 1px solid #666666"><div align="left"><?php echo obtener_financiera($_GET['fin'])?></div></td>
    <td style="border-top: 1px solid #666666"><div align="left" class="Estilo6">Estado</div></td>
    <td style="border-top: 1px solid #666666"><div align="left"><?php echo obtener_estado($_GET['estado'])?></div></td>
  </tr>
  <tr>
    <td colspan="6" style="border-top: 1px solid #666666"><table width="100%" border="0">
      <?php
      $tot=0;
      $can=0;
      $financiera=0;
      $totFin=0;
      $totCan=0;
      ?>
           
            <?php
      while (  $regcre=mysql_fetch_array($rescre)):
      ?>
      <?php if(($financiera <> $regcre['financiera']) and($financiera==0)):
                //Listo el primer encabezado
             ?>
     <tr>
          <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3"><?php echo obtener_financiera($regcre['financiera'])?></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div></td>
        </tr>
             <tr>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo9 Estilo10">Credito</div></td>
        <td width="19%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Plan</div></td>
         <td width="19%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Estado</div></td>
        <td width="16%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Cliente</div></td>
        <td width="17%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Can. Cuotas</div></td>
        <td width="20%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Imp. Cuota </div></td>
        <td width="20%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Imp. Total </div></td>

        <td width="18%" class="Estilo2" style="border: 1px solid #666666;"><div align="center">Descuenta Saldo </div>
          </td>
      </tr>
      <?php
      endif;

      if(($financiera <> $regcre['financiera']) and ($financiera<>0)):
          //Listo el resto de los encabezados con los totales de cada bloque
     ?>
          <tr>
          <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3">Total <?php echo obtener_financiera($financiera)?>: <?php echo $totFin?> - Can. de Ope: <?php echo $can;?></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div></td>
        </tr>
            <tr>
          <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3"><?php echo obtener_financiera($regcre['financiera'])?></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div></td>
        </tr>
             <tr>
        <td width="10%" style="border: 1px solid #666666"><div align="center" class="Estilo9 Estilo10">Credito</div></td>
        <td width="19%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Plan</div></td>
       <td width="19%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Estado</div></td>
        <td width="16%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Cliente</div></td>
        <td width="17%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Can. Cuotas</div></td>
        <td width="20%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Imp. Cuota </div></td>
        <td width="20%" style="border: 1px solid #666666"><div align="center" class="Estilo2">Imp. Total </div></td>

        <td width="18%" class="Estilo2" style="border: 1px solid #666666;"> <div align="center><div align="center">Descuenta Saldo </div>
          </td>
      </tr>

       <?php

      $totFin=0;
      $can=0;
      endif;
        
       ?>
     
      <tr>
        <td style="border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14"><?php echo $regcre['id'] ?></span></div></td>
        <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14"><?php echo $regcre['financiera']." ".obtener_plan($regcre['tipoplan']) ?></span></div></td>
         <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14"><?php echo obtener_estado($regcre['estado']) ?></td>
        <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14"><?php echo obtener_cliente($regcre['cliente']) ?></span></div></td>
        <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14"><?php echo $regcre['cuotas'] ?></span></div></td>
        <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14">$ <?php echo obtener_monto_cuota($regcre['id']) ?></span></div></td>
                <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14">$ <?php echo $regcre['monto'] ?> </span></div></td>
        <td style=" border-left:1px solid #666666;border-right: 1px solid #666666"><div align="center"><span class="Estilo14">
        <?php if (obtener_descuenta($regcre['tipoplan'])==0)
                echo "NO";
              else
                  echo "SI"?>
                    
                </span></div></td>


      </tr>
          
            <?php
          $financiera=$regcre['financiera'];
          $totFin=$totFin+$regcre['monto'];
          $tot=$tot+$regcre['monto'];

          $can++;
          $totCan=$totCan+1;?>


        <?php
        
 endwhile
      ?>
             <tr>
          <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3">Total <?php echo obtener_financiera($financiera)?>: <?php echo $totFin?> - Can. de Ope: <?php echo $can;?></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div>          <div align="left" class="Estilo3"></div></td>
        </tr>
  <tr>
         <td colspan="8" style="border: 1px solid #666666"><div align="left" class="Estilo3">Total: $<?php echo $tot?> - Tot. Ope. <?php echo $totCan;?></div>  </td>
       </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
    <td style="border-top: 1px solid #666666">&nbsp;</td>
  </tr>
</table>
</body>
</html>
